#pragma once
#include <iostream>
#include<string>

std::string opers = "+-*/%";

enum
{
    div_zero = 1,
    mod_zero,
    Unknown
};

class Task
{
public:
    Task(int x, int y, char oper) : _data1(x), _data2(y), _oper(oper), _result(0), _exitcode(0)
    {
    }

    void Run()
    {
        // std::cout << "run task... : " << _data1 << "+" << _data2 << "=" << _data1+_data2 << std::endl;

        switch (_oper)
        {
        case '+':
            _result = _data1 + _data2;
            break;
        case '-':
            _result = _data1 - _data2;
            break;
        case '*':
            _result = _data1 * _data2;
            break;
        case '/':
            if (_data2 == 0)
            {
                _exitcode = div_zero;
                _result = -1;
            }
            else
            {
                _result = _data1 / _data2; // 除零错误
            }
            break;
        case '%':
            if (_data2 == 0)
            {
                _exitcode = mod_zero;
                _result = -1;
            }
            else
            {
                _result = _data1 / _data2; // 除零错误
            }
            break;
        default:
            _exitcode = Unknown;
            break;
        }
    }

    std::string GetResult()
    {
        std::string r = std::to_string(_data1);
        r += _oper;
        r += std::to_string(_data2);
        r += "=";
        r += std::to_string(_result);
        r += "[code: ";
        r += std::to_string(_exitcode);
        r += "]";
        return r;
    }

    std::string GetTask()
    {
        std::string r = std::to_string(_data1);
        r += _oper;
        r += std::to_string(_data2);
        r += "= ??";
        return r;
    }

    ~Task()
    {
    }

private:
    int _data1;
    int _data2;
    char _oper;

    int _result;
    int _exitcode;
};